package com.Alan.service.order;

import com.Alan.dao.BaseDao;
import com.Alan.dao.order.OrderDao;
import com.Alan.dao.order.OrderDaoImpl;
import com.Alan.pojo.Order;

import java.sql.Connection;
import java.util.List;

public class OrderServiceImpl implements OrderService{

    private OrderDao orderDao = null;

    public OrderServiceImpl(){
        orderDao = new OrderDaoImpl();
    }


    @Override
    public int getOrderCount(String ordName, String isPay, int supId) {
        Connection connection = BaseDao.getConnection();
        int orderCount = orderDao.getOrderCount(connection, ordName, isPay, supId);

        BaseDao.closeResource(connection, null, null);
        return orderCount;
    }

    @Override
    public List<Order> getOrderList(String ordName, String isPay, int supId, int startRow, int pageRows) {
        Connection connection = BaseDao.getConnection();
        List<Order> orderList = orderDao.getOrderList(connection, ordName, isPay, supId, startRow, pageRows);

        BaseDao.closeResource(connection, null, null);
        return orderList;
    }

    @Override
    public boolean orderExist(String ordCode) {
        Connection connection = BaseDao.getConnection();
        boolean flag = false;

        if (orderDao.orderExist(connection, ordCode) > 0){
            flag = true;
        }

        BaseDao.closeResource(connection, null, null);
        return flag;
    }

    @Override
    public Order getOrderInformation(int ordId) {
        Connection connection = BaseDao.getConnection();
        Order order = orderDao.getOrderInformation(connection, ordId);

        BaseDao.closeResource(connection, null, null);
        return order;
    }

    @Override
    public boolean updateOrder(Order order) {
        Connection connection = BaseDao.getConnection();
        boolean flag = false;

        if (orderDao.updateOrder(connection, order) > 0){
            flag = true;
        }

        BaseDao.closeResource(connection, null, null);
        return flag;
    }

    @Override
    public boolean addOrder(Order order) {
        Connection connection = BaseDao.getConnection();
        boolean flag = false;

        if (orderDao.addOrder(connection, order) > 0){
            flag = true;
        }

        BaseDao.closeResource(connection, null, null);
        return flag;
    }
}
